import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";

export default {
  namespace: 'ecg',

  state: {
    ...baseState,
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    // 获取心电设备列表
    * getPageInfo({payload}, {call, put}) {

      const p = {
        ...payload,
        baseUrl: getBaseUrl(),
        process: (records) => {
          return records.map(device => {
            return {
              ...device,
              patientId: !!device.patientId ? device.patientId : '未绑定',
              state: device.state == 0 ? "离线" : "在线"
            };
          });
        }
      }

      yield put({
        type: 'baseGetPageInfo',
        payload: p
      });
    },

    // 保存和修改
    * save({payload}, {put}) {

      yield put({
        type: 'baseSave',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    },


    // 删除 之后查询分页
    * delete({payload}, {call, put, select}) {

      yield put({
        type: 'baseDelete',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    }
  }

}

function getBaseUrl() {
  return "/device/ecg/";
}
